<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
  </style>
</head>

<body>
  <h1>登陆</h1>

  <input type="text" class="username"><br>
  <input type="password" class="password"><br>
  <button class="btn">提交</button>

  <script src="js/axios.js"></script>
  <script>
    console.log(axios)
    const btn = document.querySelector('.btn')
    const username = document.querySelector('.username')
    const password = document.querySelector('.password')
    btn.onclick = () => {
      axios.post('/api/login', {
        username: username.value.trim(),
        password: password.value.trim()
      })
        // axios.get('/api/login', {
        //   params: {
        //     username: username.value.trim(),
        //     password: password.value.trim()
        //   }
        // })
        .then(res => {
          console.log(res, '前端获取到的后端返回来的数据')
          if (res.data.code === 0) {
            window.location.href = './product.html'
          }
        })
    }

  </script>
</body>

</html>